<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加管理员</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="${ctxPath}/static/police/css/common.css">
    <link rel="stylesheet" type="text/css" href="${ctxPath}/static/police/css/style.css">
</head>
<body>
<div class="embedLeft">
    <div class="breadcrumb">
        <span>权限管理</span>
        <span>管理员列表</span>
        <b>新增管理员</b>
    </div>
    <div class="embedRight">
        <form method="post" id="loginform" data-imgcode="imgcode" action="${ctxPath}/admin/manage/save">
            <input type="hidden" name="id" value="${user.id!}">
        <div class="manage_item">
            <div class="manage_line clearfix">
                <span class="label">名称</span>
                <div class="manage_int"><input  class="text" id="name" name="name" value="${user.name!}" type="text"/></div>
            </div>
            <div class="manage_line clearfix">
                <span class="label">账号</span>
                <div class="manage_int"><input  class="text" id="number" name="number"  value="${user.number!}" type="text"/></div>
            </div>
            <div class="manage_line clearfix">
                <span class="label">手机号</span>
                <div class="manage_int"><input  class="text" id="phone" name="phone"  value="${user.phone!}"  type="text"/></div>
            </div>
            <div class="manage_line clearfix">
                <span class="label">密码</span>
                <div class="manage_int"><input  class="text" id="password"  name="password"  value="${user.password!}"  type="password"/></div>
            </div>
            <div class="manage_line clearfix">
                <span class="label">负责区域</span>
                <input name="_cityCode" id="_cityCode" type="hidden" value="${cityCode!}">
                <input name="_areaCode" id="_areaCode" type="hidden" value="${areaCode!}">
                <div class="manage_int">
                    <select name="area" id="_area" style="display: inline;height:34px;">
                    </select>
                </div>
            </div>
            <div class="manage_line clearfix">
                <span class="label">权限</span>
                <div class="manage_int select_wrap">
                    <div class="select_wrap">
                        <i class="i_drop"></i>
                        <span class="select_text"></span>
                        <select name="roleId">
                            @if(isNotEmpty(role)){
                            @ for(item in role){
                            <option id="${item.id}" value="${item.id}" ${user.roleId!0 == item.id?"selected":"" }>${item.name}</option>
                            @}
                            @}
                        </select>
                    </div>
                </div>
            </div>
            <button class="blueBtn ml16 mt90" type="submit" >确认</button>
        </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="${ctxPath}/static/police/js/jquery-1.11.1.min.js"></script>
<script src="${ctxPath}/static/blade/js/blade-toolbox.js" type="text/javascript"></script>
<script src="${ctxPath}/static/blade/js/blade-ajax.js" type="text/javascript"></script>
<script src="${ctxPath}/static/layer/layer.js"></script>
<script type="text/javascript" src="${ctxPath}/static/police/js/base.js"></script>
<script type="text/javascript">
    function findProvince(){
        $.ajax({
            url: "${ctxPath}/admin/manage/findProvince",
            type: "post",
            dataType: "json",
            success: function (result) {
                if (null != result) {
                    var content = "";
                    jQuery.each(result, function (i, item) {
                        if (i == 0) {
                            content += "<option value='" + item.provinceCode + "'>" + item.province + "</option>";
                        } else {
                            content += "<option value='" + item.provinceCode + "'>" + item.province + "</option>";
                        }
                    });
                    $('#_province').append(content);
                    var provinceCode = $("#_provinceCode").val();
                    $("#_province option[value='"+provinceCode+"']").attr("selected","selected");	//根据值让option选中
                } else {
                    layer_alert('暂无省份!', "error");
                }
            }
        });
    }
    function findCity(){
        var url = '${ctxPath}/admin/manage/findCity';
        $.ajax({                            //jquery ajax
            type:'post',
            url:url,
            data:{'provinceCode':$("#_provinceCode").val()},
            dataType: "json",
            success:function (result) {
                //为了防止直辖市情况下，change条件无法触发
                $("#_city").append("<option value=''>请选择所在城市</option>");
                jQuery.each(result, function (i, item) {
                    /*循环添加所有城市列表*/
                    $("#_city").append("<option value='"+item.cityCode+"'>"+item.city+"</option>");
                    $("#_city").css('display','inline');
                });
                var cityCode = $("#_cityCode").val();
                $("#_city option[value='"+cityCode+"']").attr("selected","selected");	//根据值让option选中
            }
        });
    }
    function findArea(){
        var urlCity = '${ctxPath}/admin/manage/findArea';
        $.ajax({
            type:'post',
            url:urlCity,
            data:{'cityCode':$("#_cityCode").val(),'areaCode':$("#_areaCode").val()},
            dataType: "json",
            success:function (result) {
                jQuery.each(result,function(i,item){
                    $("#_area").append("<option  value='"+item.areaCode+"'>"+item.area+"</option>");
                    $("#_area").css('display','inline');
                });
                var areaCode = $("#_areaCode").val();
                $("#_area option[value='"+areaCode+"']").attr("selected","selected");	//根据值让option选中
            }
        })
    }
    function threeSelect(){
        /*同上*/
        $('#_city').change(function () {
            //城市更改后，更新县级数据
            $("#_area").css('display','none');
            $("#_area").children().remove();

            //清空经纬度
            $("#_lat").val('');
            $("#_lnt").val('');

            //清空详细地址
            $("#_address").val('');

            //这里的value不要和上面的重复，否则变量提升机制会覆盖掉前面的变量值
            var cityCode = this.value;
            var urlCity = '${ctxPath}/admin/manage/findArea';
            $.ajax({
                type:'post',
                url:urlCity,
                data:{'cityCode':cityCode},
                dataType: "json",
                success:function (result) {
                    jQuery.each(result,function(i,item){
                        $("#_area").append("<option  value='"+item.areaCode+"'>"+item.area+"</option>");
                        $("#_area").css('display','inline');
                    });
                }
            })

        });
    }
    // findProvince();
    findCity();
    findArea();
    threeSelect();	//加载三级下拉框
    // 登录
    $("form").submit(function(){

        if($("#name").val() == ""){
            alert("请输入名称");
            return false;
        }

        if($("#number").val() == ""){
            alert("请输入账号");
            return false;
        }

        if($("#phone").val() == ""){
            alert("请输入手机号");
            return false;
        }

        if($("#password").val() == ""){
            alert("请输入密码");
            return false;
        }
        if($("#_area").val() == null){
            alert("请选择区域");
            return false;
        }

        var $form = $(this);
        var ajax = new Ajax($form.attr("action"), function(data){
            if (data.code === 0) {
                layer.msg(data.message, {shift: 1});
                setTimeout(function(){$("#iframepage", parent.document).attr("src","${ctxPath}/admin/manage/");}, 1200);
                return false;
            } else {
                layer.msg(data.message, {shift: 6});
                return false;
            }
        });
        ajax.data = $form.serialize();
        ajax.start();

        return false;
    });
</script>
</body>
</html>